﻿using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components.Routing;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Messhall.Framework.Converts;
using Messhall.HostService.Interface.Permission;
using Messhall.HostService.Proxy;

namespace Messhall.UI.Permission.Shared;

public partial class MainLayout
{
    private bool UseTabSet { get; set; } = true;

    private string Theme { get; set; } = "";

    private bool IsOpen { get; set; }

    private bool IsFixedHeader { get; set; } = true;

    private bool IsFixedFooter { get; set; } = true;

    private bool IsFullSide { get; set; } = true;

    private bool ShowFooter { get; set; } = true;

    private List<MenuItem> Menus { get; set; }

    private Dictionary<string, string> TabItemTextDictionary { get; set; }

    [NotNull] private IEnumerable<BreadcrumbItem>? DataSource { get; set; }

    /// <summary>
    /// OnInitialized 方法
    /// </summary>
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        // 模拟异步线程切换，正式代码中删除此行代码
        await Task.Yield();

        // 菜单获取可以通过数据库获取，此处为示例直接拼装的菜单集合
        TabItemTextDictionary = new()
        {
            [""] = "Index"
        };
        Menus = await GetIconSideMenuItems();

        DataSource = new List<BreadcrumbItem>
        {
            new BreadcrumbItem("Home", "#"),
            new BreadcrumbItem("Library", "#"),
            new BreadcrumbItem("Data")
        };
    }

    private async Task<List<MenuItem>> GetIconSideMenuItems()
    {
        // IPermission permissionService = ServiceFactory.Create<IPermission>();
        //
        // var tree = await permissionService.GetTreeAsync();
        //
        // return Mapping.Convert<List<MenuItem>>(tree);

        var menus = new List<MenuItem>
        {
            new MenuItem() { Text = "跳转组件库", Icon = "fa fa-fw fa-home", Url = "https://www.blazor.zone/components" },


            new MenuItem()
            {
                Text = "系统权限", Icon = "fa fa-fw fa-table", Url = "table", IsActive = true,
                Items = new List<MenuItem>()
                {
                    new MenuItem() { Text = "角色", Icon = "fa fa-fw fa-database", Url = "/Role/List" },
                    new MenuItem() { Text = "用户", Icon = "fa fa-fw fa-database", Url = "/Users/List" },
                    new MenuItem() { Text = "菜单设置", Icon = "fa fa-fw fa-database", Url = "/Pemission/List" },
                }
            },
        };

        return menus;
    }
}